<template>
    <div>
        <el-table :data="roleList" border style="width: 100%">
            <el-table-column prop="id" label="角色编号">
            </el-table-column>
            <el-table-column prop="rolename" label="角色名称">
            </el-table-column>
            <el-table-column prop="status" label="状态">
                <template slot-scope="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success">启用</el-tag>
                        <el-tag type="danger" v-else>禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" circle icon="el-icon-edit" @click="edit(item.row.id)">
                        </el-button>
                        <el-button type="danger" circle icon="el-icon-delete" @click="del(item.row.id)">
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
// 引入辅助性函数
import { roleDelete } from "../../request/api"
import { mapGetters, mapActions } from 'vuex';
export default {
    data() {
        return {
            tableData: [{
                date: '2016-05-03',
                name: '王小虎',
                province: '上海',
                city: '普陀区',
                address: '上海市普陀区金沙江路 1518 弄',
                zip: 200333
            }, {
                date: '2016-05-02',
                name: '王小虎',
                province: '上海',
                city: '普陀区',
                address: '上海市普陀区金沙江路 1518 弄',
                zip: 200333
            }]
        };
    },
    methods: {
        // 点击编辑按钮
        edit(id) {
            this.$emit("edit", id)
        },
        //获取角色列表数据
        ...mapActions({
            getRoleList: "role/roleList_Action"
        }),
        // 点击删除按钮
        del(id) {
            // 调用删除接口
            roleDelete({ id }).then(res => {
                if (res.code == 200) {
                    this.$message.success(res.msg);
                    // 重新渲染角色列表数据
                    this.getRoleList()
                } else {
                    this.$message.error(res.msg);
                }
            })
        }
    },
    computed: {
        ...mapGetters({
            roleList: "role/getRoleList"
        })
    },
    mounted() {
        this.getRoleList()
    }
};
</script>

<style scoped>
</style>
